package com.idbk.chargestation.util;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.idbk.chargestation.api.ChargeStationURL;
import com.idbk.chargestation.dialog.DialogShare;

import java.util.Locale;

public class OtherUtil {
	
	public static void share(Context context,int pointId,String pointName) {	
		DialogShare dialog = new DialogShare(context, getShareURL(pointId), pointName);
		dialog.show();//显示分享Dialog
	}
	
	private static String getShareURL(int id) {
		String path = "/api/station/pile!sharePoint.do?model.pointId=%d";
		String url = String.format(Locale.CHINA, path, id);
		return ChargeStationURL.getAbsoluteApiUrlFromRoot(url);
	}
	
	/**
	 * 动态设置ListView高度
	 * @param listView listView
	 */
	public static void setListViewHeightBasedOnChildren(ListView listView) { 
		if(listView == null) return; 
		ListAdapter listAdapter = listView.getAdapter(); 
		if (listAdapter == null) { 
			// pre-condition 
			return; 
		} 
		int totalHeight = 0; 
		for (int i = 0; i < listAdapter.getCount(); i++) { 
			View listItem = listAdapter.getView(i, null, listView); 
			listItem.measure(0, 0); 
			totalHeight += listItem.getMeasuredHeight(); 
		} 
		ViewGroup.LayoutParams params = listView.getLayoutParams(); 
		params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
		listView.setLayoutParams(params); 
	}
	
	
}
